package com.swak.zookeeper;

import java.util.concurrent.TimeUnit;

import com.swak.boot.config.zookeeper.ZookeeperProperties;
import com.swak.boot.config.zookeeper.ZookeeperAutoConfiguration;
import com.swak.leader.Leader;

/**
 * 测试选主
 * 
 * @author 618lf
 */
public class LeaderTest2 {

	public static void main(String[] args) throws Exception {
		System.out.println("连接ZK服务器...");
		ZookeeperProperties properties = new ZookeeperProperties();
		properties.setAddress("192.168.137.100:2181");
		// properties.setUsername("admin");
		// properties.setPassword("admin");
		ZookeeperAutoConfiguration configuration = new ZookeeperAutoConfiguration();
		ZookeeperService zookeeperService = configuration.zookeeperService(properties);

		System.out.println("连接ZK服务器...[成功]");
		Leader leader = zookeeperService.leaderSelect("/job/WechatJob/Leader");

		while (true) {
			System.out.println(leader.isMe());
			TimeUnit.SECONDS.sleep(10);
		}
	}
}
